﻿

//Js获得URL参数
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var url = decodeURI( window.location.search);
    var r = url.substr(1).match(reg);
    if (r != null) {
        var value = unescape(r[2]).replace(/fdandsign/, "&");
        return value;
    }
    return null;
}
//function getUrlParam(name) {
//    //构造一个含有目标参数的正则表达式对象
//    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//    //匹配目标参数
//    var r = window.location.search.substr(1).match(reg);
//    //alert(r);
//    //返回参数值
//    if (r != null) return decodeURI(r[2]);
//    return null;
//}

function messageShow(msg) {
    //layer.alert(msg);
    //alert(msg);
    Dialog.alert(msg);
}
function msgTimeout() {
    Dialog.alert("登录超时");

}

//function messageConfirm(msg){
//    Dialog.confirm('警告：您确认要要删除吗？',function(){Dialog.alert("yeah，删除成功！")});

//}

function submitForm(obj) {

    var parentForm = getBelongFormElement($(obj));
    if (parentForm.length > 0) {
        $(parentForm).submit();
    }

}

function jasonDate(jsondate) {
    var dateMilliseconds = parseInt(jsondate.EditTime.replace(/\D/igm, ""));
    //实例化一个新的日期格式，使用1970 年 1 月 1 日至今的毫秒数为参数
    var date = new Date(dateMilliseconds);
    return date.toLocaleString();

}


function layuidatetimeFormatter(value,fomatter) {   

    try {        
        
        var dateMilliseconds = parseInt(value.replace(/\D/igm, ""));

        //实例化一个新的日期格式，使用1970 年 1 月 1 日至今的毫秒数为参数
        //
        

        var date = new Date(dateMilliseconds);
        var strDate = date.pattern(fomatter);
        return strDate;
    } catch (e) {
        return "";
    }
}
function formatNum(strNum) {
    return (strNum || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
    //if (strNum.length <= 3) {
    //    return strNum;
    //}
    //if (!/^(\+|-)?(\d+)(\.\d+)?$/.test(strNum)) {
    //    return strNum;
    //}
    //var a = RegExp.$1,
    //    b = RegExp.$2,
    //    c = RegExp.$3;
    //var re = new RegExp();
    //re.compile("(\\d)(\\d{3})(,|$)");
    //while (re.test(b)) {
    //    b = b.replace(re, "$1,$2$3");
    //}
    //return a + "" + b + "" + c;
}
function formatPercent(value) {
    if (value) {
        return value + "%";
    } else {
        return "";
    }

}

//$(function () {

//});
//$('document').ajaxError(function (event, xhr, settrings) {
//    alert('请求失败后');
//});


function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}

//获取cookie
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
}


function getLayuitablefield(layuitableths) {
    var _fieldtitle = "";
    _fieldtitle += "[";
   
    for (var i = 0; i < layuitableths.length; i++) {
        var $layuitableth = $(layuitableths[i]);
        var datafield = $layuitableth.attr("data-field");
        var title = $layuitableth.find("span").first().html();
        if (!isNaN(parseInt(datafield, 10))) {
            continue;
        }
        _fieldtitle += "{ field: '" + datafield + "',title:'" + title + "'},";
    }
    _fieldtitle += "]";

    return _fieldtitle;
}
var DownLoadFile = function (options) {
    var config = $.extend(true, { method: 'post' }, options);
    var $iframe = $('<iframe id="down-file-iframe" />');
    var $form = $('<form target="down-file-iframe" method="' + config.method + '" />');
    $form.attr('action', config.url);
    for (var key in config.data) {
        $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
    }
    $iframe.append($form);
    $(document.body).append($iframe);
    $form[0].submit();
    $iframe.remove();
}



